use std::io::{Result};
use super::raw::Raw;
use super::mbox::MBox;

#[derive(Debug,Default,Clone,Copy)]
pub struct Meta(Raw);

impl Meta {
    pub fn init(meta:Raw) -> Self { Self(meta) }
    pub fn attach<T>(&self,offset:usize) -> Result<MBox<T>> {
        MBox::<T>::attach(&self.0 ,offset)
    }
    pub fn reset<T>(&self,data:T,offset:usize) -> bool {
        match self.attach::<T>(offset) {
            Ok(mut b) => {
                b.reset(data);
                true
            },
            Err(_) => false,
        }
    }
}